package com.yiwei.jmx.util;

import android.content.Context;
import android.os.Build;
import android.support.v4.app.Fragment;
import android.view.View;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.drawable.GlideDrawable;
import com.bumptech.glide.request.animation.GlideAnimation;
import com.bumptech.glide.request.target.ViewTarget;
import com.yiwei.jmx.R;

/**
 * Created by xsooy-pc on 18-8-29.
 */

public class GlideUtil {
    public static void loadImg(Fragment context,int res, View target){
        Glide.with(context).load(res)
                .into(new ViewTarget<View, GlideDrawable>(target) {
                    //括号里为需要加载的控件
                    @Override
                    public void onResourceReady(GlideDrawable resource,
                                                GlideAnimation<? super GlideDrawable> glideAnimation) {
                        if (Build.VERSION.SDK_INT >= 16) {
                            this.view.setBackground(resource.getCurrent());
                        } else {
                            this.view.setBackgroundDrawable(resource.getCurrent());
                        }
                    }
                });
    }

    public static void loadImg(Context context, int res, View target){
        Glide.with(context).load(res)
                .into(new ViewTarget<View, GlideDrawable>(target) {
                    //括号里为需要加载的控件
                    @Override
                    public void onResourceReady(GlideDrawable resource,
                                                GlideAnimation<? super GlideDrawable> glideAnimation) {
                        if (Build.VERSION.SDK_INT >= 16) {
                            this.view.setBackground(resource.getCurrent());
                        } else {
                            this.view.setBackgroundDrawable(resource.getCurrent());
                        }
                    }
                });
    }

    public static void loadImg(Context context, String res, View target){
        Glide.with(context).load(res)
                .into(new ViewTarget<View, GlideDrawable>(target) {
                    //括号里为需要加载的控件
                    @Override
                    public void onResourceReady(GlideDrawable resource,
                                                GlideAnimation<? super GlideDrawable> glideAnimation) {
                        if (Build.VERSION.SDK_INT >= 16) {
                            this.view.setBackground(resource.getCurrent());
                        } else {
                            this.view.setBackgroundDrawable(resource.getCurrent());
                        }
                    }
                });
    }
}
